<?php

namespace app\api\server\entity;

use app\api\model\entity\EntityStageNameLogoApiModel;
use app\api\model\entity\EntityStageNameLogoTypeApiModel;
use app\api\ServerBase;
use think\Request;

class EntityStageNameLogoServer extends ServerBase
{
    protected $model;
    protected $request;
    /**
     * @var mixed
     */
    protected $param;
    /**
     * @var mixed
     */
    protected $validate;
    /**
     * @var EntityStageNameLogoTypeApiModel
     */
    private $typeModel;

    function __construct(Request $request)
    {
        $this->request = $request;
        $this->param = $request->param();
        $this->model = new EntityStageNameLogoApiModel();
        $this->typeModel=new EntityStageNameLogoTypeApiModel();
    }

    function getType(){
        $where=[];
        $where['pid'] = $this->param['pid']??0;
        $list = $this->typeModel
            ->where('status',1)
            ->where($where)
            ->field('id,title,pid')
            ->order('sort desc,id desc')->select();
        $this->getMessageCode('adminMessage.success.select',2);
        return $list;
    }
    function getTree(){
        $list = $this->typeModel->getTree(1,'id,title,pid');
        $this->getMessageCode('adminMessage.success.select',2);
        return $list;
    }
    function getList(){
        [$page,$limit] = $this->getPage($this->param);
        $field= 'id,title,type_id,img,price,sale,original_price,introduction';
        $this->param['status'] = 1;
        [$list,$count] = $this->model->getApiList($this->param,[],$field,$page,$limit);
        $result['data']=$list;
        $result['count']=$count;
        $this->getMessageCode('adminMessage.success.select',2);
        return $result;
    }

    function getDetail(){
        $id =  $this->request->param('id');
        $info = $this->model->details($id,'id,title,content,type_id,img,price,sale,original_price');
        if(empty($info)){
            $this->getMessageCode('code_common.not_find',1);
            return false;
        }
        $this->getMessageCode('adminMessage.success.select',2);
        return $info;
    }
}